package com.anos.smsfun.activities;

import android.app.ActionBar;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

import android.view.View;
import com.anos.smsfun.R;
import com.anos.smsfun.adapter.TabsAdapter;
import com.anos.smsfun.fragment.ContactsFragment;
import com.anos.smsfun.fragment.SMSFragment;
import com.anos.smsfun.fragment.SettingFragment;

public class MainActivity extends FragmentActivity {

    private ViewPager mViewPager;
    private TabsAdapter mTabsAdapter;

    // private boolean doubleBackToExitPressedOnce = false;

    /**
     * ON CREATE
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // find view id
        findViewIdAll();

        final ActionBar actionBar = getActionBar();
        // Specify that tabs should be displayed in the action bar.
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);

        // setup view pager
        mTabsAdapter = new TabsAdapter(this, mViewPager);

        /** Tab Actionbar */
        mTabsAdapter.addTab(
                actionBar
                        .newTab()
                        .setText(getString(R.string.tab_sms))
                        .setIcon(
                                getResources().getDrawable(
                                        R.drawable.perm_group_messages_blue)
                        ),
                SMSFragment.class, null
        );
        mTabsAdapter.addTab(
                actionBar
                        .newTab()
                        .setText(getString(R.string.tab_contact))
                        .setIcon(
                                getResources().getDrawable(
                                        R.drawable.orca_people_icon_selected)
                        ),
                ContactsFragment.class, null
        );
        mTabsAdapter.addTab(
                actionBar
                        .newTab()
                        .setText(getString(R.string.tab_setting))
                        .setIcon(
                                getResources().getDrawable(
                                        R.drawable.orca_me_icon_selected)
                        ),
                SettingFragment.class, null
        );

        if (savedInstanceState != null) {
            actionBar.setSelectedNavigationItem(savedInstanceState.getInt(
                    "tab", 0));
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {

        super.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
    }


    /**
     * find view by id all
     */
    private void findViewIdAll() {
        mViewPager = (ViewPager) findViewById(R.id.pager);
    }
}
